<template>
  <div class="category">
    <van-search
      @click="openPopup"
      shape="round"
      background="#fff"
      disabled
      placeholder="请输入搜索关键词"
    />
    <transition name="slide">
      <router-view></router-view>
    </transition>
    <div class="content">
      <div class="content_left">
        <van-sidebar v-model="activeKey">
          <van-sidebar-item
            v-for="item in categoryList"
            :key="item.id"
            :title="item.name"
            @click="barClick(item.id)"
          />
        </van-sidebar>
      </div>
      <div class="content_right">
        <Banner :currentCategory="currentCategory" />
      </div>
    </div>
  </div>
</template>
 
<script>
import { GetCatelogDataApi, GetCurrentDataApi } from "../request/api";
import Banner from "../components/category/Banner";
export default {
  data() {
    return {
      categoryList: [],
      activeKey: 0,
      currentCategory: [],
      subCategoryList: [],
      id: "1005000",
    };
  },
  created() {
    GetCatelogDataApi().then((res) => {
      // console.log(res);
      this.categoryList = res.data.categoryList;
      // console.log(this.categoryList);
    });
    // GetCurrentDataApi({ id: 1005000 }).then((res) => {
    //   // console.log(res);
    //   this.currentCategory = res.data.currentCategory;
    //   // console.log(this.currentCategory);
    // });
    this.barClick(this.id);
  },
  methods: {
    openPopup() {
      this.$router.push("/category/popup");
    },
    barClick(id) {
      this.id = id;
      GetCurrentDataApi({ id: this.id }).then((res) => {
        this.currentCategory = res.data.currentCategory;
        // console.log(this.currentCategory);
      });
    },
  },
  components: {
    Banner,
  },
};
</script>
 
<style lang = "less">
.category {
  position: relative;
  min-height: 100%;
}
.slide-enter,
.slide-leave-to {
  right: -100%;
}
.slide-enter-active,
.slide-leave-active {
  transition: right 0.5s linear;
}
.slide-enter-to,
.slide-leave {
  right: 0;
}
.content {
  .content_left {
    float: left;
    width: 80px;
    background-color: #f7f8fa;
    .van-sidebar {
      height: calc(100vh - 54px);
    }
  }
  .content_right {
    width: calc(100vw - 80px);
    height: calc(100vh - 54px);
    float: right;
    background-color: #fff;
  }
}
</style>